
#include "StdAfx.h"
#include "AsyncEventCaller.h"

CAsyncEventCaller::CAsyncEventCaller(BOOL bAutoRegister)
: m_dwCallerID(0)
, m_bRegister(FALSE)
{
	if(bAutoRegister)
		RegisterAsyncCaller();
}

CAsyncEventCaller::~CAsyncEventCaller(void)
{
	UnregisterAsyncCaller();
}

void CAsyncEventCaller::CallAsyncEventProc(__int64 nProcPtr, DWORD dwEvent, DWORD_PTR dwParam, LPVOID pExpandedParam, UINT nExpandedParamSize, BOOL bSync)
{
	if(!m_bRegister)
		return;

	theAsyncEventManager.CallAsyncEventProc(m_dwCallerID, nProcPtr, dwEvent, dwParam, pExpandedParam, nExpandedParamSize, bSync);
}

void CAsyncEventCaller::RegisterAsyncCaller()
{
	if(!m_bRegister)
	{
		m_dwCallerID = theAsyncEventManager.RegisterCaller(this);
		m_bRegister = TRUE;
	}

}

void CAsyncEventCaller::UnregisterAsyncCaller()
{
	if(m_bRegister)
	{
		theAsyncEventManager.UnregisterCaller(m_dwCallerID);
		m_bRegister = FALSE;
	}
}

